<template>
  <div class="cs-page-container">

    <el-tabs value="second" type="border-card" @tab-click="handleClick">
      <el-tab-pane label="真人认证" name="first" />
      <el-tab-pane label="主播认证" name="second" />

      <div class="cs-filter-container">
        <el-input
          v-model.trim="listQuery.userId"
          clearable
          placeholder="请输入用户ID"
        />
        <el-select
          v-model="listQuery.type"
          placeholder="审核类型"
        >
          <el-option label="未审核" :value="0" />
          <el-option label="已审核" :value="1" />
        </el-select>
        <el-date-picker
          v-model="daterangeValue"
          :picker-options="daterangePickerOptions"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="创建起始时间"
          end-placeholder="创建结束时间"
          value-format="yyyy-MM-dd"
          @change="daterangeChanged"
        />
        <el-button
          type="primary"
          size="small"
          icon="el-icon-search"
          @click="handleFilter"
        >搜索</el-button>
        <el-button
          type="info"
          size="small"
          icon="el-icon-refresh-right"
          @click="resetFilter"
        >重置</el-button>
      </div>

      <div class="cs-filter-result">
        <el-table
          v-loading="listLoading"
          :data="list"
          :height="'calc(100vh - 200px)'"
          row-key="recordId"
          border
          fit
          size="small"
          highlight-current-row
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
        >
          <el-table-column
            align="center"
            label="用户ID"
            prop="userId"
          >

            <template slot-scope="{ row }">
              <TooptipsCom :user-id="row.userId" />
            </template>
          </el-table-column>

          <el-table-column
            align="center"
            label="昵称"
          >
            <template slot-scope="{ row }">{{ row.nickname }}</template>
          </el-table-column>

          <el-table-column
            align="center"
            label="年龄"
          >
            <template slot-scope="{ row }">{{ row.age }}</template>
          </el-table-column>

          <el-table-column
            align="center"
            label="头像"
          >
            <template slot-scope="{ row }">
              <image-tooltip :image-id="row.avatar">
                <img
                  v-if="row.avatar"
                  slot="img"
                  :src="row.avatar"
                  width="100"
                  @click="zoomImage(row.avatar)"
                >
              </image-tooltip>
            </template>
          </el-table-column>

          <el-table-column
            align="center"
            label="封面"
          >
            <template slot-scope="{ row }">
              <image-tooltip :image-id="row.backgroundImage">
                <img
                  v-if="row.backgroundImage"
                  slot="img"
                  :src="row.backgroundImage"
                  width="100"
                  @click="zoomImage(row.backgroundImage)"
                >
              </image-tooltip>
            </template>
          </el-table-column>

          <el-table-column
            align="center"
            label="视频"
          >
            <template slot-scope="{row}">
              <div
                v-if="row.video"
                class="video-wrap"
                @click="zoomVideo(row.video)"
              >
                <video
                  controls
                  :src="row.video"
                  width="100"
                  style="cursor:pointer"
                  title="点击放大"
                />
              </div>
            </template>
          </el-table-column>

          <el-table-column
            align="center"
            label="身份信息"
            width="210"
          >
            <template slot-scope="{ row }">
              <tr>
                真实姓名：{{ row.realName }}
              </tr>
              <tr>
                身份证号：{{ row.idNumber }}
              </tr>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="联系电话"
          >
            <template slot-scope="{ row }">{{ row.mobile }}</template>
          </el-table-column>

          <el-table-column
            align="center"
            label="提审时间"
            min-width="140"
          >
            <template slot-scope="{ row }">{{ row.applyTime | parseTime }}</template>
          </el-table-column>

          <el-table-column
            v-if="isCheckedStatus"
            align="center"
            label="审核状态"
          >
            <template slot-scope="{ row }">{{ row.status | filterCheckStatus }}</template>
          </el-table-column>

          <el-table-column
            align="center"
            label="操作"
            fixed="right"
            width="160"
          >
            <template v-if="row.status !== 1 && row.status !== 2" slot-scope="{ row }">
              <el-button
                type="primary"
                size="mini"
                @click="onVerify(row, '1')"
              >通过</el-button>
              <el-button
                v-if="!row.banedStatus"
                type="danger"
                size="mini"
                @click="onVerify(row, '2')"
              >不通过</el-button>
            </template>
          </el-table-column>
        </el-table>
        <TablePagination
          :current-page="listQuery.page"
          :limit="listQuery.limit"
          :total="total"
          :loading="listLoading"
          @handleSizeChange="handleSizeChange"
          @handleCurrentChange="handleCurrentChange"
        />
      </div>
      <ImageViewer
        :visible.sync="showImage"
        :url="imageUrl"
        :type="imageViewerType"
      />
    </el-tabs>
  </div>
</template>

<script>
import TablePagination from '@/components/TablePagination'
import ImageViewer from '@/components/ImageViewer'

import { xhrAnchorAuditList, xhrAnchorAudit } from '@api/anchor'
import AnchorMixin from './mixin'
export default {
  name: 'AnchorAudit',
  components: { TablePagination, ImageViewer },
  mixins: [AnchorMixin],
  data() {
    return {
      list: null,
      total: 0,
      listQuery: {
        page: 1,
        type: 0,
        limit: 100
      },
      daterangeValue: '',
      showImage: false,
      videoUrl: '',
      imageUrl: '',
      imageViewerType: null
    }
  },
  created() {
    this.doSearch()
  },
  methods: {
    doSearch() {
      if (!this.validateParams(this.listQuery)) {
        return
      }
      this.handleCheckedStatus()
      xhrAnchorAuditList(this.listQuery)
        .then(resp => {
          this.list = resp.data.list
          this.total = resp.data.total
          this.listLoading = false
        })
        .catch(err => {
          this.$message.error(err)
          this.listLoading = false
        })
    },
    zoomVideo(url) {
      this.showImage = true
      this.imageViewerType = 'video'
      this.imageUrl = url
    },
    zoomImage(url) {
      this.showImage = true
      this.imageViewerType = 'image'
      this.imageUrl = url
    },
    onVerify(row, status) {
      const title = status === '1' ? '通过' : '拒绝'
      this.$confirm('确定' + title + '审核？').then(() => {
        xhrAnchorAudit({
          record: row,
          // recordId: row.recordId,
          status
        })
          .then(resp => {
            this.$message.success('操作成功')
            this.doSearch()
          })
          .catch(err => {
            this.$message.error(err)
          })
      })
    },
    handleClick(tab) {
      switch (tab.name) {
        case 'first':
          this.$router.push('/anchor/anchor-auth')
          break
      }
    }
  }
}
</script>
<style lang="scss" scoped>
  .video-wrap {
    position: relative;
    video {
      width: 100%;
    }
    &::after {
      content: '';
      position: absolute;
      width: 100%;
      height: 100%;
      left: 0;
      top: 0;
    }
  }
</style>
